<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title></title>
    <script type="text/javascript" xmlns:th="http://www.thymeleaf.org" charset="utf-8" th:inline="javascript"></script>
</head>
<body>
<div class="layuimini-main">
    <div class="layui-form layuimini-form">
        <input type="text" style="display: none" name="sID" th:value="${id}">
        <div class="layui-form-item">
            <label class="layui-form-label required">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="sName" lay-verify="required" lay-reqtext="姓名不能为空"
                       placeholder="请输入姓名" class="layui-input" th:value="${sname}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">性别</label>
            <div class="layui-input-block" th:if="${ssex=='男'}">
                <input type="radio" name="sSex" value="男" title="男" checked="checked">
                <input type="radio" name="sSex" value="女" title="女">
            </div>
            <div class="layui-input-block" th:if="${ssex=='女'}">
                <input type="radio" name="sSex" value="男" title="男">
                <input type="radio" name="sSex" value="女" title="女" checked="checked">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label" required>年龄</label>
            <div class="layui-input-block">
                <input type="text" name="sAge" lay-verify="required" lay-reqtext="年龄不能为空"
                       placeholder="请输入年龄" class="layui-input" th:value="${sage}">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="updateBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script>
    layui.use(['form', 'table'], function () {

        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(updateBtn)', function (data) {
            var datas=data.field;
            datas.sAge=parseInt(datas.sAge);
            $.ajax({
                url:"student/updateStudent",
                type:"POST",
                data:datas,
                success:function (result){
                    if (result.code==200){
                        layer.msg("修改成功",{
                            icon:6,
                            time:500
                        },function (){
                            parent.window.location.reload();
                            layer.close(index);
                            layer.close(parentIndex);
                        });
                    }else {layer.msg("修改失败");}
                }
            })

            return false;
        });

    });
</script>